<?php

namespace app\admin\service\statistics\datatable\fast;


use app\admin\service\statistics\datatable\AbstractComputeStatistician;
use app\admin\service\statistics\traits\CompletionTrait;


/**
 * 问题占比
 * Class FastConsultingRate
 * @package app\admin\service\statistics\datatable\fast
 */
class FastConsultingRate extends AbstractComputeStatistician
{
    // 前置数据
    protected array $statisticians = [
        'uv' => FastUvCount::class,
        'consulting_paid_count' => FastConsultingCount::class,
    ];

    // 补齐
    use CompletionTrait;

    protected function compute(int $index)
    {
        $statisticiansData = $this->statisticiansData;

        $uv = $statisticiansData['uv'][$index]['value'] ?? null;

        $consulting_count = $statisticiansData['consulting_count'][$index]['value'] ?? null;

        if (!is_numeric($uv) || !is_numeric($consulting_count)) {
            return '';
        }

        return show_percentage($consulting_count, $uv, 1);
    }

    protected function getDefaultValue()
    {
        return '0%';
    }
}